package com.hinnotek.amoeba.viewmodels

import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.CompanyPurchaseByCompanyPurchaseIdBean
import com.hinnotek.amoeba.bean.old.CompanyPurchaseByUserIdBean
import com.hinnotek.amoeba.bean.old.PtCustomerProjectBean
import com.hinnotek.amoeba.bean.old.PtProjectDetailBean
import com.hinnotek.amoeba.repo.AmibaCustomerRepo
import com.lee.common.base.BaseViewModel
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class AmibaCustomerViewModel @Inject constructor(private val repository: AmibaCustomerRepo) :
    BaseViewModel() {

    private val baseData = StateLiveData<BaseBean>()
    private val ptProjectDetailData = StateLiveData<PtProjectDetailBean>()
    private val ptCustomerProjectData = StateLiveData<MutableList<PtCustomerProjectBean>>()
    private val companyPurchaseByUserIdData = StateLiveData<MutableList<CompanyPurchaseByUserIdBean>>()

    fun addProject(body: RequestBody): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.addProject(body, baseData)
        }
        return baseData
    }

    fun addCustomer(customerName: String, orgId: Int, createUser: String): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.addCustomer(customerName, orgId, createUser, baseData)
        }
        return baseData
    }

    fun getCustomerProjectById(amibaCustomerProjectId: Int): StateLiveData<PtProjectDetailBean> {
        viewModelScope.launch {
            repository.getCustomerProjectById(amibaCustomerProjectId, ptProjectDetailData)
        }
        return ptProjectDetailData
    }

    fun getProjectPageByCustomerId(customerId: Int, pageNo: Int, pageSize: Int) :StateLiveData<MutableList<PtCustomerProjectBean>>{
        viewModelScope.launch {
            repository.getProjectPageByCustomerId(customerId,pageNo,pageSize, ptCustomerProjectData)
        }
        return ptCustomerProjectData
    }


    fun addCompanyPurchase(body: RequestBody): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.addCompanyPurchase(body, baseData)
        }
        return baseData
    }

    private val companyPurchaseByCompanyPurchaseIdData = StateLiveData<CompanyPurchaseByCompanyPurchaseIdBean>()


    fun getCompanyPurchaseByCompanyPurchaseId(companyPurchaseId: Int):StateLiveData<CompanyPurchaseByCompanyPurchaseIdBean> {
        viewModelScope.launch {
            repository.getCompanyPurchaseByCompanyPurchaseId(companyPurchaseId, companyPurchaseByCompanyPurchaseIdData)
        }
        return   companyPurchaseByCompanyPurchaseIdData
    }

    fun getCompanyPurchaseByUserId(applyUserId: Int, pageNo: Int, pageSize: Int) :StateLiveData<MutableList<CompanyPurchaseByUserIdBean>>{
        viewModelScope.launch {
            repository.getCompanyPurchaseByUserId(applyUserId,pageNo,pageSize, companyPurchaseByUserIdData)
        }
        return   companyPurchaseByUserIdData
    }
}